//
//  LocalSerialIOPackTransport.h
//  RunSketch
//
//  Created by Brian on 9/5/09.
//  Copyright 2009 Tellart. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "IOPackTransport.h"
#import "IOPack.h"

#import <stdio.h>
#import <string.h>
#import <unistd.h>
#import <fcntl.h>
#import <errno.h>
#import <termios.h>

@interface LocalSerialIOPackTransport : NSObject <IOPackTransport>
{
    BOOL hasBeenSetUp;
    
    IOPack *ioPack;

    int fileDescriptor;
    struct termios options;
    struct termios oldOptions;
    
    unsigned int	readBufferSize;
	char            *readBuffer;
    
    NSString        *deviceAddress;
    
}

- (void)connectToDev:(NSString*)devPath;

/** private methods - do not call directly! **/
- (void) allocReadBuffer;
- (void) deallocReadBuffer;
- (BOOL) openPort;
- (void) closePort;

/** Begin IOPackTransport implementation **/
@property (nonatomic, retain, readonly) NSString *deviceAddress;
@property (nonatomic, retain) IOPack *ioPack;
- (int)numOutputChannels;
- (int)numInputChannels;
- (BOOL)isConnectedAndReady;
- (BOOL)isReadable;
- (BOOL)isWritable;
/*
- (int)readData:(NSMutableData*)data;
- (int)readDataAndReplace:(NSMutableData*)data;
*/
- (int)read;
- (void)writeData:(NSData*)data;
/** End IOPackTransport implementation **/

@end
